%%{init: {'themeVariables': { 'fontSize': '12px'}}}%%
graph TD
    classDef path fill:#eee,stroke:#000,color:#000
    classDef plan fill:#fff,stroke-width:1px,color:#000
    classDef itemplan fill:#fff,stroke-width:2px,color:#000
    classDef unbatchedplan fill:#dff,stroke-width:1px,color:#000
    classDef sideeffectplan fill:#fcc,stroke-width:2px,color:#000
    classDef bucket fill:#f6f6f6,color:#000,stroke-width:2px,text-align:left

    subgraph "Buckets for queries/conditions/include-all-archived"
    Bucket0("Bucket 0 (root)<br /><br />1: <br />ᐳ: 10, 11, 42, 44, 45, 12, 14, 27<br />2: PgSelect[9]<br />3: PgSelectRows[15]"):::bucket
    Bucket1("Bucket 1 (listItem)<br />Deps: 12, 42, 27<br /><br />ROOT __Item{1}ᐸ15ᐳ[16]"):::bucket
    Bucket2("Bucket 2 (nullableBoundary)<br />Deps: 17, 12, 42, 27<br /><br />ROOT PgSelectSingle{1}ᐸforumsᐳ[17]<br />1: <br />ᐳ: 18, 19, 24<br />2: PgSelect[20]<br />3: PgSelectRows[28]"):::bucket
    Bucket3("Bucket 3 (listItem)<br />Deps: 12<br /><br />ROOT __Item{3}ᐸ28ᐳ[29]"):::bucket
    Bucket4("Bucket 4 (nullableBoundary)<br />Deps: 30, 12<br /><br />ROOT PgSelectSingle{3}ᐸmessagesᐳ[30]<br />1: <br />ᐳ: 31, 32<br />2: PgSelect[33]<br />3: PgSelectRows[38]<br />ᐳ: First[37], PgSelectSingle[39]"):::bucket
    Bucket5("Bucket 5 (nullableBoundary)<br />Deps: 39<br /><br />ROOT PgSelectSingle{4}ᐸusersᐳ[39]"):::bucket
    end
    Bucket0 --> Bucket1
    Bucket1 --> Bucket2
    Bucket2 --> Bucket3
    Bucket3 --> Bucket4
    Bucket4 --> Bucket5

    %% plan dependencies
    PgSelect9[["PgSelect[9∈0] ➊<br />ᐸforumsᐳ<br />More deps:<br />- Object[12]<br />- Constantᐸ2ᐳ[42]"]]:::plan
    Lambda14{{"Lambda[14∈0] ➊<br />ᐸincludeArchivedConditionᐳ<br />More deps:<br />- Constantᐸ[ undefined, 'YES' ]ᐳ[44]"}}:::plan
    Lambda14 --> PgSelect9
    Object12{{"Object[12∈0] ➊<br />ᐸ{pgSettings,withPgClient}ᐳ<br />Dependents: 3"}}:::plan
    Access10{{"Access[10∈0] ➊<br />ᐸ2.pgSettingsᐳ"}}:::plan
    Access11{{"Access[11∈0] ➊<br />ᐸ2.withPgClientᐳ"}}:::plan
    Access10 & Access11 --> Object12
    __Value2["__Value[2∈0] ➊<br />ᐸcontextᐳ"]:::plan
    __Value2 --> Access10
    __Value2 --> Access11
    PgSelectRows15[["PgSelectRows[15∈0] ➊"]]:::plan
    PgSelect9 --> PgSelectRows15
    Lambda27{{"Lambda[27∈0] ➊<br />ᐸincludeArchivedConditionᐳ<br />More deps:<br />- Constantᐸ[HIDDEN]ᐳ[45]"}}:::plan
    __Item16[/"__Item[16∈1]<br />ᐸ15ᐳ"\]:::itemplan
    PgSelectRows15 ==> __Item16
    PgSelectSingle17{{"PgSelectSingle[17∈1]<br />ᐸforumsᐳ"}}:::plan
    __Item16 --> PgSelectSingle17
    PgSelect20[["PgSelect[20∈2]<br />ᐸmessagesᐳ<br />More deps:<br />- Object[12]<br />- Constantᐸ2ᐳ[42]"]]:::plan
    PgClassExpression19{{"PgClassExpression[19∈2]<br />ᐸ__forums__.”id”ᐳ"}}:::plan
    PgClassExpression24{{"PgClassExpression[24∈2]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
    PgClassExpression19 & PgClassExpression24 & Lambda27 --> PgSelect20
    PgClassExpression18{{"PgClassExpression[18∈2]<br />ᐸ__forums__.”name”ᐳ"}}:::plan
    PgSelectSingle17 --> PgClassExpression18
    PgSelectSingle17 --> PgClassExpression19
    PgSelectSingle17 --> PgClassExpression24
    PgSelectRows28[["PgSelectRows[28∈2]"]]:::plan
    PgSelect20 --> PgSelectRows28
    __Item29[/"__Item[29∈3]<br />ᐸ28ᐳ"\]:::itemplan
    PgSelectRows28 ==> __Item29
    PgSelectSingle30{{"PgSelectSingle[30∈3]<br />ᐸmessagesᐳ"}}:::plan
    __Item29 --> PgSelectSingle30
    PgSelect33[["PgSelect[33∈4]<br />ᐸusersᐳ<br />More deps:<br />- Object[12]"]]:::plan
    PgClassExpression32{{"PgClassExpression[32∈4]<br />ᐸ__messages...author_id”ᐳ"}}:::plan
    PgClassExpression32 --> PgSelect33
    PgClassExpression31{{"PgClassExpression[31∈4]<br />ᐸ__messages__.”body”ᐳ"}}:::plan
    PgSelectSingle30 --> PgClassExpression31
    PgSelectSingle30 --> PgClassExpression32
    First37{{"First[37∈4]"}}:::plan
    PgSelectRows38[["PgSelectRows[38∈4]"]]:::plan
    PgSelectRows38 --> First37
    PgSelect33 --> PgSelectRows38
    PgSelectSingle39{{"PgSelectSingle[39∈4]<br />ᐸusersᐳ"}}:::plan
    First37 --> PgSelectSingle39
    PgClassExpression40{{"PgClassExpression[40∈5]<br />ᐸ__users__.”username”ᐳ"}}:::plan
    PgSelectSingle39 --> PgClassExpression40
    PgClassExpression41{{"PgClassExpression[41∈5]<br />ᐸ__users__....vatar_url”ᐳ"}}:::plan
    PgClassExpression40 o--o PgClassExpression41

    %% define steps
    classDef bucket0 stroke:#696969
    class Bucket0,__Value2,PgSelect9,Access10,Access11,Object12,Lambda14,PgSelectRows15,Lambda27 bucket0
    classDef bucket1 stroke:#00bfff
    class Bucket1,__Item16,PgSelectSingle17 bucket1
    classDef bucket2 stroke:#7f007f
    class Bucket2,PgClassExpression18,PgClassExpression19,PgSelect20,PgClassExpression24,PgSelectRows28 bucket2
    classDef bucket3 stroke:#ffa500
    class Bucket3,__Item29,PgSelectSingle30 bucket3
    classDef bucket4 stroke:#0000ff
    class Bucket4,PgClassExpression31,PgClassExpression32,PgSelect33,First37,PgSelectRows38,PgSelectSingle39 bucket4
    classDef bucket5 stroke:#7fff00
    class Bucket5,PgClassExpression40,PgClassExpression41 bucket5

